package com.fr.dialog.core;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.io.Serializable;

public class LeftCenterRightLayout
  implements LayoutManager, Serializable
{
  public static final String LEFT = "LEFT";
  public static final String CENTER = "CENTER";
  public static final String RIGHT = "RIGHT";
  private Component leftComponent;
  private Component centerComponent;
  private Component rightComponent;

  public void addLayoutComponent(String paramString, Component paramComponent)
  {
    synchronized (paramComponent.getTreeLock())
    {
      if (paramString == null)
        paramString = "centerup";
      if ("LEFT".equals(paramString))
        this.leftComponent = paramComponent;
      else if ("CENTER".equals(paramString))
        this.centerComponent = paramComponent;
      else if ("RIGHT".equals(paramString))
        this.rightComponent = paramComponent;
      else
        throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + paramString);
    }
  }

  public void removeLayoutComponent(Component paramComponent)
  {
    synchronized (paramComponent.getTreeLock())
    {
      if (paramComponent == this.leftComponent)
        this.leftComponent = null;
      else if (paramComponent == this.centerComponent)
        this.centerComponent = null;
      else if (paramComponent == this.rightComponent)
        this.rightComponent = null;
    }
  }

  public Dimension preferredLayoutSize(Container paramContainer)
  {
    synchronized (paramContainer.getTreeLock())
    {
      Dimension localDimension1 = new Dimension(0, 0);
      Dimension localDimension2 = this.leftComponent.getPreferredSize();
      Dimension localDimension3 = this.centerComponent.getPreferredSize();
      Dimension localDimension4 = this.rightComponent.getPreferredSize();
      localDimension1.width += localDimension2.width + localDimension3.width + localDimension4.width;
      localDimension1.height += localDimension2.height;
      Insets localInsets = paramContainer.getInsets();
      localDimension1.width += localInsets.left + localInsets.right;
      localDimension1.height += localInsets.top + localInsets.bottom;
      return localDimension1;
    }
  }

  public Dimension minimumLayoutSize(Container paramContainer)
  {
    synchronized (paramContainer.getTreeLock())
    {
      Dimension localDimension1 = new Dimension(0, 0);
      Dimension localDimension2 = this.leftComponent.getMinimumSize();
      Dimension localDimension3 = this.centerComponent.getMinimumSize();
      Dimension localDimension4 = this.rightComponent.getMinimumSize();
      localDimension1.width += localDimension2.width + localDimension3.width + localDimension4.width;
      localDimension1.height += localDimension2.height;
      Insets localInsets = paramContainer.getInsets();
      localDimension1.width += localInsets.left + localInsets.right;
      localDimension1.height += localInsets.top + localInsets.bottom;
      return localDimension1;
    }
  }

  public void layoutContainer(Container paramContainer)
  {
    synchronized (paramContainer.getTreeLock())
    {
      Insets localInsets = paramContainer.getInsets();
      int i = localInsets.top;
      int j = paramContainer.getHeight() - localInsets.bottom;
      int k = localInsets.left;
      int l = paramContainer.getWidth() - localInsets.right;
      Dimension localDimension = this.centerComponent.getPreferredSize();
      int i1 = localDimension.width;
      int i2 = (l - k - i1) / 2;
      this.leftComponent.setBounds(k, i, i2, j - i);
      this.centerComponent.setBounds(k + i2, i, i1, j - i);
      this.rightComponent.setBounds(l - i2, i, i2, j - i);
    }
  }
}